﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using HigLabo.Net;

namespace HigLabo.WindowsAzure.RestService.ServiceManagement
{
    public class CreateDeploymentCommand : ManagementServiceCommand<CreateDeploymentResult>
    {
        public String ServiceName { get; private set; }
        public DeploymentSlot Slot { get; private set; }
        public CreateDeploymentBody RequestBody { get; private set; }

        public CreateDeploymentCommand(String serviceName, DeploymentSlot slot, CreateDeploymentBody requestBody)
        {
            if (String.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentException("serviceName must not be null", "serviceName");
            }
            if (requestBody == null)
            {
                throw new ArgumentNullException("requestBody");
            }
            this.ServiceName = serviceName;
            this.Slot = slot;
            this.RequestBody = requestBody;
        }
        public override string GetRequestUri()
        {
            var slt = "";
            switch (this.Slot)
            {
                case DeploymentSlot.Staging:
                    slt = "staging";
                    break;
                case DeploymentSlot.Production:
                    slt = "production";
                    break;
                default:
                    throw new NotImplementedException("DeploymentSlot");
            }
            return String.Format("services/hostedservices/{0}/deploymentslots/{1}", this.ServiceName, slt);
        }
        public override HttpMethodName MethodName
        {
            get { return HttpMethodName.Post; }
        }
        public override string ContentType
        {
            get { return "application/xml"; }
        }
        public override Dictionary<String, String> GetRequestHeaders()
        {
            return null;
        }
        public override System.IO.Stream GetRequestBodyStream()
        {
            return this.GetStream(this.RequestBody.CreateText());
        }

    }
}
